package com.ehome.poct.base.api.vo.log;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.DesensitizedUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;


public class DefaultPhoneSerializer extends JsonSerializer<String> {

    @Override
    public void serialize(String phone, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (CharSequenceUtil.isNotBlank(phone)) {
            jsonGenerator.writeString(DesensitizedUtil.mobilePhone(phone));
        } else {
            jsonGenerator.writeString(phone);
        }
    }
}
